package com.plant.es.test.client_version.handler.action;

import com.plant.es.test.client_version.handler.EsInterface;
import org.elasticsearch.client.RequestOptions;
import org.elasticsearch.client.RestHighLevelClient;
import org.elasticsearch.client.indices.GetIndexRequest;
import org.elasticsearch.client.indices.GetIndexResponse;

import java.io.IOException;

/**
 * 1.索引相关操作
 */
public class IndexRelated implements EsInterface {
    @Override
    public void process(RestHighLevelClient esClient) throws IOException {


        // 增加索引 create index
//        CreateIndexRequest request = new CreateIndexRequest("user");
//        CreateIndexResponse response = esClient.indices().create(request, RequestOptions.DEFAULT);
//        boolean acknowledged = response.isAcknowledged();
//        System.out.println("响应状态：" + acknowledged);

        //获取索引内容
        GetIndexRequest getIndexRequest = new GetIndexRequest("user");
        GetIndexResponse getIndexResponse = esClient.indices().get(getIndexRequest, RequestOptions.DEFAULT);
        System.out.println(getIndexResponse.getAliases());
        System.out.println(getIndexResponse.getMappings());
        System.out.println(getIndexResponse.getSettings());

        //删除索引
//        DeleteIndexRequest deleteIndexRequest = new DeleteIndexRequest("user");
//        AcknowledgedResponse response = esClient.indices().delete(deleteIndexRequest, RequestOptions.DEFAULT);
//        boolean acknowledged = response.isAcknowledged();
//        System.out.println("响应状态：" + acknowledged);
    }

        /*
        索引数据格式：
        {
            "user": {
                "aliases": {},
                "mappings": {},
                "settings": {
                    "index": {
                        "creation_date": "1648640714370",
                        "number_of_shards": "1",
                        "number_of_replicas": "1",
                        "uuid": "iQkCoh4dQkuzErlgUtYjNg",
                        "version": {
                            "created": "7080099"
                        },
                        "provided_name": "user"
                    }
                }
            }
        }
        */
}
